export function myPiniaPlugin1({ options }: { options: any }) {
  console.log("🚀 ~ myPiniaPlugin1 ~ options:", options);
  return {
    secret: "the cake is a lie",
  };
}

export function myPiniaPlugin2(context: any) {
  const { store } = context;
  store.test = "this is a test";
}

export function myPiniaPlugin3(context: any) {
  const { store } = context;
  if (store.$id === "counter") {
    store.name = "my name is pinia";
  }
}

export function myPiniaPlugin4(context: any) {
  const { store } = context;
  const originState = deepClone(store.$state);
  store.$reset = function () {
    store.$patch(deepClone(originState));
  };
}

function deepClone(obj: any) {
  if (typeof obj !== "object" || obj === null) {
    return obj;
  }

  let newObj: { [key: string]: any } = Array.isArray(obj) ? [] : {};
  for (const key in obj) {
    newObj[key] = deepClone(obj[key]);
  }

  return newObj;
}
